<template>
  <div>
    <Search :search="search" :reset="reset">
      <template v-slot:body>
        <el-form-item label="分步式调拨单号" prop="docno">
          <el-input v-model="query.docno" name="docno" clearable />
        </el-form-item>
        <el-form-item label="组织代码" prop="org_code">
          <el-input v-model="query.org_code" name="org_code" clearable />
        </el-form-item>
        <!-- <el-form-item label="单据类型" prop="order_type">
          <el-select v-model="query.order_type" placeholder="请选择" clearable>
            <el-option :label="item.label" :value="item.value" v-for="item in TransferOrderTypeList" :key="item.value" />
          </el-select>
        </el-form-item> -->
        <el-form-item label="单据状态" prop="trans_status">
          <el-select v-model="query.trans_status" placeholder="请选择" clearable>
            <el-option :label="item.label" :value="item.value" v-for="item in TransferOrderStatusList" :key="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="金蝶状态" prop="status">
          <el-select v-model="query.status" placeholder="请选择" clearable>
            <el-option :label="item.label" :value="item.value" v-for="item in stateList" :key="item.value" />
          </el-select>
        </el-form-item>
      </template>
    </Search>
    <div class="table-default">
      <!-- <Operate :show="open" /> -->
      <el-table :data="tableData" v-loading="loading" border>
        <el-table-column prop="docno" label="分步式调拨单号" />
        <el-table-column prop="org_code" label="组织代码" />
        <el-table-column prop="order_type" label="单据类型">
          <template #default="scope">
            {{ TransferOrderTypeObj[scope.row.order_type] }}
          </template>
        </el-table-column>
        <el-table-column prop="trans_status" label="单据状态">
          <template #default="scope">
            {{ TransferOrderStatusObj[scope.row.trans_status] }}
          </template>
        </el-table-column>
        <el-table-column prop="status" label="金蝶状态">
          <template #default="scope">
            <el-tag class="ml-2" type="primary" v-if="scope.row.status == 0">{{ stateObj[scope.row.status] }}</el-tag>
            <el-tag class="ml-2" type="success" v-if="scope.row.status == 1">{{ stateObj[scope.row.status]  }}</el-tag>
            <el-tag class="ml-2" type="error" v-if="scope.row.status == 2">{{ stateObj[scope.row.status]  }}</el-tag>
          </template>
        </el-table-column>

        <el-table-column label="操作" width="100">
          <template #default="scope">
            <router-link :to="{ path: '/inventory/setbyDetail', query: { id: `${scope.row.id}` } }">
              <Show />
            </router-link>
          </template>
        </el-table-column>
      </el-table>
      <Paginate />
    </div>
  </div>
</template>

<script lang="ts" setup>
import { computed, onMounted } from 'vue'
import { useGetList } from '/admin/composables/curd/useGetList'
import { useDestroy } from '/admin/composables/curd/useDestroy'
import { useOpen } from '/admin/composables/curd/useOpen'
import http from '/admin/support/http'
import { setTableHeight } from '/admin/utils/setHeight.js'

const api = 'inventory/transfer/order?order_type=2'

const { data, query, search, reset, loading } = useGetList(api)
const { destroy, deleted } = useDestroy()
const { open, close, title, visible, id } = useOpen()

const tableData = computed(() => data.value?.data)

let stateList = ref([])
let stateObj = ref({})
let TransferOrderTypeList = ref([])
let TransferOrderTypeObj = ref({})
let TransferOrderStatusList = ref([])
let TransferOrderStatusObj = ref({})

const getState = () => {
  http.get('options/DocStatus').then(r => {
    console.log('金蝶状态：', r.data.data)
    stateList.value = r.data.data
    stateObj.value = stateList.value.reduce((prev, item) => {
      prev[item.value] = item.label
      return prev
    }, {})
  })
  http.get('options/TransferOrderType').then(r => {
    console.log('调拨单类型', r.data.data)
    TransferOrderTypeList.value = r.data.data
    TransferOrderTypeObj.value = TransferOrderTypeList.value.reduce((prev, item) => {
      prev[item.value] = item.label
      return prev
    }, {})
  })
  http.get('options/TransferOrderStatus').then(r => {
    console.log('调拨单状态', r.data.data)
    TransferOrderStatusList.value = r.data.data
    TransferOrderStatusObj.value = TransferOrderStatusList.value.reduce((prev, item) => {
      prev[item.value] = item.label
      return prev
    }, {})
  })
}

getState()

onMounted(() => {
  search()
  deleted(reset)
  setTableHeight('.table-default')
})
</script>

<style>
.el-table {
  height: 87%;
}
</style>